/*
* Copyright (C) 2004-2010  Autodesk, Inc.
* 
* This library is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser
* General Public License as published by the Free Software Foundation.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*
*/

#include "stdafx.h"
#include "FdoWcsField.h"
#include "FdoWcsXmlGlobals.h"

FdoWcsField::FdoWcsField(void)
{
}

FdoWcsField::~FdoWcsField(void)
{
}

FdoWcsField* FdoWcsField::Create()
{
    return new FdoWcsField();
}

void FdoWcsField::Dispose()
{
    delete this;
}

FdoXmlSaxHandler* FdoWcsField::XmlStartElement(FdoXmlSaxContext *context, FdoString *uri, FdoString *name, FdoString *qname, FdoXmlAttributeCollection *atts)
{
    FdoXmlSaxHandler* pRet = NULL;

    try
    {
        VALIDATE_ARGUMENT(context);
        VALIDATE_ARGUMENT(name);

        pRet = BaseType::XmlStartElement(context, uri, name, qname, atts);
        if (pRet == NULL)
        {
            if (FdoCommonOSUtil::wcsicmp(name, FdoWcsXmlGlobals::WcsCapabilitiesCoverageTitle) == 0 ||
                FdoCommonOSUtil::wcsicmp(name, FdoWcsXmlGlobals::WcsCapabilitiesCoverageAbstract) == 0 ||
                FdoCommonOSUtil::wcsicmp(name, FdoWcsXmlGlobals::WcsCapabilitiesCoverageIdentifier) == 0 ||
                FdoCommonOSUtil::wcsicmp(name, FdoWcsXmlGlobals::WcsCapabilitiesCoverageKeyword) == 0 )
            {
                mXmlContentHandler = FdoXmlCharDataHandler::Create();
                pRet = mXmlContentHandler;
            }
        }
    }
    catch (FdoException* e)
    {
        context->AddError(e);
        e->Release();
    }

    return pRet;
}

FdoBoolean FdoWcsField::XmlEndElement(FdoXmlSaxContext *context, FdoString *uri, FdoString *name, FdoString *qname)
{
    try
    {
        VALIDATE_ARGUMENT(context);
        VALIDATE_ARGUMENT(name);

        if (FdoCommonOSUtil::wcsicmp(name, FdoWcsXmlGlobals::WcsCapabilitiesCoverageTitle) == 0)
            SetTitle(mXmlContentHandler->GetString());
        else if (FdoCommonOSUtil::wcsicmp(name, FdoWcsXmlGlobals::WcsCapabilitiesCoverageAbstract) == 0)
            SetAbstract(mXmlContentHandler->GetString());
        else if (FdoCommonOSUtil::wcsicmp(name, FdoWcsXmlGlobals::WcsCapabilitiesCoverageIdentifier) == 0)
            SetIdentifier(mXmlContentHandler->GetString());
        else if (FdoCommonOSUtil::wcsicmp(name, FdoWcsXmlGlobals::WcsCapabilitiesCoverageKeyword) == 0)
        {
            FdoStringsP keywords = GetKeywordList();
            keywords->Add(mXmlContentHandler->GetString());
        }
    }
    catch (FdoException* ex) 
    {
        context->AddError(ex);
        ex->Release();
    }

    return BaseType::XmlEndElement(context, uri, name, qname);
}

FdoString* FdoWcsField::GetIdentifier() const
{
    return mIdentifier;
}

void FdoWcsField::SetIdentifier(FdoString* identifier)
{
    mIdentifier = identifier;
}

FdoString* FdoWcsField::GetTitle() const
{
    return mTitle;
}

void FdoWcsField::SetTitle(FdoString *title)
{
    mTitle = title;
}

FdoString* FdoWcsField::GetAbstract() const
{
    return mAbstract;
}

void FdoWcsField::SetAbstract(FdoString *abstract)
{
    mAbstract = abstract;
}

FdoStringCollection* FdoWcsField::GetKeywordList() const
{
    return FDO_SAFE_ADDREF(mKeywordList.p);
}